//
//  ViewController.m
//  30301
//
//  Created by student on 16/3/18.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property(nonatomic,weak)CALayer *layer;
@property(nonatomic,strong)UIView *moveView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
  //1.设置图片的CALayer
    //圆角
    self.imageView.layer.cornerRadius=50;
    
    //边框
    self.imageView.layer.borderColor=[UIColor yellowColor].CGColor;
    self.imageView.layer.borderWidth=10;
    
    //超出边框的内容剪裁掉
    //self.imageView.layer.masksToBounds=YES;
    
    //阴影
    self.imageView.layer.shadowColor=[UIColor blackColor].CGColor;
    //阴影的偏移
    self.imageView.layer.shadowOffset=CGSizeMake(20, 20);
    
    //阴影的宽度
    self.imageView.layer.shadowRadius=20;
    
    //阴影的透明度
    self.imageView.layer.shadowOpacity=1.0f;
    
    //2.新建一个CALayer对象
    
//    CALayer *layer=[CALayer layer];
//    
//    layer.frame=CGRectMake(100, 200, 100, 100);
//    
//    layer.cornerRadius=10;
//    
//    layer.masksToBounds=YES;
//    
//    //layer.contents=(id)[UIImage imageNamed:@"2.png"].CGImage;
//    
//    layer.backgroundColor=[UIColor redColor].CGColor;
//    
//    [self.view.layer addSublayer:layer];
//    
//    self.layer=layer;
    
    //.3
    
    self.moveView=[[UIView alloc]initWithFrame:CGRectMake(100, 150, 80, 80)];
    [self.view addSubview:self.moveView];
    self.layer=self.moveView.layer;
    



}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//    [UIView beginAnimations:nil context:nil];
//    [UIView setAnimationDuration:3];
//    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    
    CGSize winSize=[UIScreen mainScreen].bounds.size;
    
    //self.layer.position=CGPointMake(arc4random_uniform(winSize.width), arc4random_uniform(winSize.height));
    self.layer.cornerRadius = arc4random_uniform(1);
    
    self.layer.backgroundColor = [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1].CGColor;
    
    self.layer.borderColor = [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:arc4random_uniform(255)/255.0].CGColor;
    
    self.layer.borderWidth = arc4random_uniform(1);
    
//self.layer.transform = CATransform3DMakeRotation(arc4random_uniform(M_PI*2), 1, 0, 0);
    
    [UIView commitAnimations];


}
@end
